import os
from datetime import date

__all__ = ('CONFIGS', 'LOGGER_DICT')


class BaseConfig(object):
    DEBUG = True
    BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    LOG_DIR = os.path.join(BASE_PATH, 'logs')


class DevelopmentConfig(BaseConfig):
    SECRET_KEY = "^3g@#%BCG&qFsdaJHSD()#JBfdsd"


class TestingConfig(BaseConfig):
    SECRET_KEY = "^G&qgqB**(FsdaJHSD()#JBfdsd"


class ProductionConfig(BaseConfig):
    DEBUG = False
    SECRET_KEY = "^G&qgqB*#daJHSD()#JBfdsd"


CONFIGS = {
    "dev": DevelopmentConfig,
    "prod": ProductionConfig,
    "test": TestingConfig,
}

if not os.path.exists(BaseConfig.LOG_DIR):
    os.makedirs(BaseConfig.LOG_DIR, mode=0o755)

LOGGER_DICT = {
    'version': 1,
    'formatters': {
        'simple': {
            'format': "%(asctime)s  %(filename)s : %(levelname)s  %(message)s"
        }
    },
    'handlers': {
        'stream': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'simple'
        },
        'default': {
            'level': 'INFO',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'formatter': 'simple',
            'filename': BaseConfig.LOG_DIR + f"/{date.today()}.log",
            'interval': 1,
            'when': 'D',
            'backupCount': 30,
            'encoding': 'utf-8'
        }
    },
    'root': {
        'level': 'INFO',
        'handlers': ['default', 'stream']
    },
    'loggers': {
        '': {
            'handlers': ['default', 'stream'],
            'level': 'INFO',
            'propagate': True,
        }
    }
}
